package com.sxf.controller.blog;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.WebRequest;

import com.sxf.controller.formbean.PostVO;
import com.sxf.querybean.PostQuery;
import com.sxf.service.PostService;

@Controller
@RequestMapping("blog")
public class ContentController {
	@Resource
	private PostService postService;

	@RequestMapping(value = "/show/content/{year}/{month}/{day}/{postName}", method = {
			RequestMethod.GET, RequestMethod.POST })
	public String showContentByDate(@PathVariable("year") String year,
			@PathVariable("month") String month,
			@PathVariable("day") String day,
			@PathVariable("postName") String postName) {

		return "blog/content/content";
	}

	@Deprecated
	@RequestMapping(value = "/show/content", method = { RequestMethod.GET,
			RequestMethod.POST })
	public String showContentByP(@RequestParam("p") String p,
			WebRequest request) {
		if (StringUtils.isNotBlank(p)) {
			long postId = Long.parseLong(p);
			PostQuery postQuery = new PostQuery();
			postQuery.setId(postId);
			List<PostVO> postList = postService.queryList(postQuery);
			if (postList != null && !postList.isEmpty()) {
				request.setAttribute("post", postList.get(0),
						WebRequest.SCOPE_REQUEST);
			}
		}
		return "blog/content/content";
	}
}
